package com.mjw.zstu.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mjw.zstu.entity.Product;
import com.mjw.zstu.mapper.ProductMapper;
import com.mjw.zstu.resultDto.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class ProductService {
    @Autowired
    ProductMapper productMapper;
    public JsonResult add(Product product){
        product.setIs_delete(0);
        int success=productMapper.insert(product);
        return new JsonResult(200,"添加成功",null);
    }
    public JsonResult delete(int id){
        Product product=new Product();
        product.setId(id);
        product.setIs_delete(1);
        productMapper.updateById(product);
//        productMapper.deleteById(id);
        return new JsonResult(200,"删除成功",null);
    }
    public JsonResult getProcuctSelfExhibition(int id,int company_id){
        Product product = new Product();
        product.setCompany_id(company_id);
        product.setExhibition_id(id);
        QueryWrapper<Product> productQueryWrapper=new QueryWrapper<>(product);
        productQueryWrapper.eq("is_delete",0);
        return new JsonResult(200,"获取成功",productMapper.selectList(productQueryWrapper));
    }
    public JsonResult exhibitionProduct(int exhibition_id){
        Product product = new Product();
        product.setExhibition_id(exhibition_id);
        QueryWrapper<Product> productQueryWrapper=new QueryWrapper<>(product);
        productQueryWrapper.eq("is_delete",0);
        return new JsonResult(200,"获取成功",productMapper.selectList(productQueryWrapper));
    }
    public  JsonResult editProduct(Product product){
        productMapper.updateById(product);
        return new JsonResult(200,"修改成功",null);
    }
    public JsonResult getdetail( int product_id){
        Product product=new Product();
        product.setId(product_id);
        Wrapper<Product> productWrapper=new QueryWrapper<>(product);
       Product product1= productMapper.selectOne(productWrapper);
        return new JsonResult(200,"获取成功",product1);
    }
    public JsonResult getExhibitionProducts(int id){
        Product product=new Product();
        product.setExhibition_id(id);
        Wrapper<Product> productWrapper=new QueryWrapper<>(product);
      List<Product> l= productMapper.selectList(productWrapper);
      return new JsonResult(200,"获取成功",l);
    }
}
